var v = null;
var st = null;
function fingerReaderInit(type, noDownMsg) {//1:孚恩2：东大
    if (!v) {
        try {
            v = new ActiveXObject("ValidationModuleDll.ValidationScanner");
            st = new ActiveXObject("ValidationModuleDll.ComScannerStruct");
        } catch (e) {
            pushMessage(e.description, "error", 3);
            v = null;
            st = null;
            if (!noDownMsg) {
                var d = confirm("插件未启动或需要下载，是否下载？错误信息【" + e + "】");
                if (d) {
                    location.assign("/st_edsl/ocx/ReleaseOCX.exe");
                }
            }
            return false;
        }
        st.avlScannerTimeout = 10;
        st.AvlMatcherFastMode = 10;
    }
    var b = false;
    try {
        b = v.ClientInit(st, type);
    } catch (e) {
        b = false;
    }
    if (b == false) {
        pushMessage("指纹仪初始化失败，请检查仪器是否正常连接！", "error", 3);
    }

    if (type == 1) {
        b = v.ClientUpdateScanner();
        if (b == false) {
            throw (new Error("ClientUpdateScanner == false"));
        }
    }
    return true;
}

function fingerReaderUnInit() {
    if (v) {
        v.ClientUninit();
        v = null;
    }
}

function verify(f1, f2) {
    return v.ClientBegionVerify(f1, f2);
}

function fingerUsersMatch(srcFingerprint, srcFingerprintList) {
    return v.FingerUsersMatch(srcFingerprint, srcFingerprintList);
}

/**采集指纹
 * @param callback 参数：指纹特征（string）
 * @returns
 */
function readFinger(callback) {
    var njf1 = njen(this, arguments, "callback");
    nj: while (1) {
        switch (njf1.cp) {
            case 0:
                njf1._f = v.ClientBegionScanner();
            case 1:
                njf1.cp = ((!njf1._f) || njf1._callback(njf1._f)) ? 2 : 3;
                break;
            case 2:
                njf1.pc(4, null, sleep, [1000]);
            case 4:
                with (njf1)
                    if ((rv4 = f.apply(c, a)) == NJSUS) {
                        return fh;
                    }
                njf1._f = v.ClientBegionScanner();
                njf1.cp = 1;
                break;
            case 3:
                break nj;
        }
    }
}
/**采集指纹（非阻塞）
 * @param callback 参数：指纹特征（string）
 * @returns
 */
function readFingerThread(callback) {
    var njf1 = njen(this, arguments, "callback");
    nj: while (1) {
        switch (njf1.cp) {
            case 0:
                njf1._f = v.GetFingerTz();
            case 1:
                njf1.cp = ((!njf1._f) || njf1._callback(njf1._f)) ? 2 : 3;
                break;
            case 2:
                njf1.pc(4, null, sleep, [1000]);
            case 4:
                with (njf1)
                    if ((rv4 = f.apply(c, a)) == NJSUS) {
                        return fh;
                    }
                njf1._f = v.GetFingerTz();
                njf1.cp = 1;
                break;
            case 3:
                break nj;
        }
    }
}
/**采集指纹与图像
 * @param callback 参数：指纹特征与BMP格式图片（string[] 0:特征1：图片base64）
 * @returns
 */
function readFingerImage(callback) {
    var njf1 = njen(this, arguments, "callback");
    nj: while (1) {
        switch (njf1.cp) {
            case 0:
                njf1._f = v.GetFingerImage();
            case 1:
                njf1.cp = ((!njf1._f) || njf1._callback(njf1._f)) ? 2 : 3;
                break;
            case 2:
                njf1.pc(4, null, sleep, [1000]);
            case 4:
                with (njf1)
                    if ((rv4 = f.apply(c, a)) == NJSUS) {
                        return fh;
                    }
                njf1._f = v.GetFingerImage();
                njf1.cp = 1;
                break;
            case 3:
                break nj;
        }
    }
}
/**采集指纹与图像（非阻塞）
 * @param callback 参数：指纹特征与BMP格式图片（string[] 0:特征1：图片base64）
 * @returns
 */
function readFingerImageThread(callback) {
    var njf1 = njen(this, arguments, "callback");
    nj: while (1) {
        switch (njf1.cp) {
            case 0:
                njf1._f = v.GetFingerImageAsync();
            case 1:
                njf1.cp = ((!njf1._f) || njf1._callback(njf1._f)) ? 2 : 3;
                break;
            case 2:
                njf1.pc(4, null, sleep, [1000]);
            case 4:
                with (njf1)
                    if ((rv4 = f.apply(c, a)) == NJSUS) {
                        return fh;
                    }
                njf1._f = v.GetFingerImageAsync();
                njf1.cp = 1;
                break;
            case 3:
                break nj;
        }
    }
}
